import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../controllers/user_controller.dart';

import '../../utils/resability.dart';

class ForgotPasswordStepOnePage extends StatelessWidget {
  ForgotPasswordStepOnePage({super.key});

  final ForgotPasswordController forgotPasswordController = Get.put(
    ForgotPasswordController(),
  );
  final TextEditingController _emailController = TextEditingController();
  final TextEditingController _captchaController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: bg_color, // 深色背景
      body: SingleChildScrollView(
        padding: EdgeInsets.all(40.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(height: 60),
            Align(
              alignment: Alignment.centerLeft,
              child: IconButton(
                onPressed: () => Get.back(),
                icon: Icon(Icons.arrow_back_ios, color: Colors.white),
              ),
            ),
            SizedBox(height: 30),

            Align(
              alignment: Alignment.centerLeft,
              child: Text(
                '找回密码',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 40,
                  fontWeight: FontWeight.w200,
                ),
              ),
            ),
            SizedBox(height: 70),
            // 邮箱输入框
            TextField(
              controller: _emailController,
              cursorColor: Colors.grey,
              decoration: InputDecoration(
                labelText: '邮箱',
                labelStyle: TextStyle(color: Colors.grey),
                prefixIcon: Icon(Icons.person, color: Colors.grey),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(10),
                  borderSide: BorderSide(color: Colors.grey),
                ),
                focusedBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(10),
                  borderSide: BorderSide(color: Colors.white),
                ),
              ),
              style: TextStyle(color: Colors.white),
            ),
            SizedBox(height: 24),

            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Flexible(
                  flex: 2,
                  child: TextField(
                    controller: _captchaController,
                    cursorColor: Colors.grey,
                    decoration: InputDecoration(
                      labelText: '验证码',
                      labelStyle: TextStyle(color: Colors.grey),
                      prefixIcon: Icon(Icons.message, color: Colors.grey),
                      border: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10),
                        borderSide: BorderSide(color: Colors.grey),
                      ),
                      focusedBorder: OutlineInputBorder(
                        borderRadius: BorderRadius.circular(10),
                        borderSide: BorderSide(color: Colors.white),
                      ),
                    ),
                    style: TextStyle(color: Colors.white),
                  ),
                ),
                Flexible(
                  flex: 1,
                  child: Obx(
                    () => TextButton(
                      onPressed:
                          forgotPasswordController.is_button_enable.value
                              ? forgotPasswordController.startCountdown
                              : null,
                      child: Text(
                        forgotPasswordController.is_button_enable.value
                            ? '获取验证码'
                            : '${forgotPasswordController.countdown.value}s后再试',
                        style: TextStyle(color: Colors.white),
                      ),
                    ),
                  ),
                ),
              ],
            ),
            SizedBox(height: 32),

            // 确认按钮
            SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(
                  backgroundColor: button_color,
                  padding: EdgeInsets.symmetric(vertical: 16),
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10),
                  ),
                ),
                onPressed: () {
                  // 获取输入框内容
                  final email = _emailController.text;
                  final captcha = _captchaController.text;

                  forgotPasswordController.forgotPasswordStepOne(
                    email,
                    captcha,
                  );
                },
                child: Text(
                  '提交',
                  style: TextStyle(fontSize: 16, color: Colors.white),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
